package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.Goods;
import com.atguigu.jxc.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author zjr
 * @version 1.0
 */
@RequestMapping("/goods/")
@RestController
public class GoodsController {
    @Autowired
    GoodsService service;
    @PostMapping("list")
    public Map<String,Object> goodsList(Integer page, Integer rows, String goodsName, Integer goodsTypeId){
        return service.list(page,rows,goodsName,goodsTypeId);
    }
    @PostMapping("save")
    public ServiceVO saveGoods(@RequestParam(value = "goodsId",required = false)Integer goodsId, Goods goods){
        return service.saveGoods(goodsId,goods);
    }
    @PostMapping("delete")
    public ServiceVO deleteByGoodsId(Integer goodsId){
        return service.deleteById(goodsId);
    }
    @PostMapping("getNoInventoryQuantity")
    public Map<String,Object> getNoInventoryQuantity(Integer page,Integer rows,String nameOrCode){
        return service.getNoInventoryQuantity(page,rows,nameOrCode);
    }
    @PostMapping("getHasInventoryQuantity")
    public Map<String,Object> getHasInventoryQuantity(Integer page,Integer rows,String nameOrCode){
        return service.getHasInventoryQuantity(page,rows,nameOrCode);
    }
    @PostMapping("saveStock")
    public ServiceVO saveStock(Integer goodsId,Integer inventoryQuantity,double purchasingPrice){
        return service.saveStock(goodsId,inventoryQuantity,purchasingPrice);
    }
    @PostMapping("deleteStock")
    public ServiceVO deleteStock(Integer goodsId){
        return service.deleteStockById(goodsId);
    }
}
